package com.inno.life.controller.controller;

import com.google.common.base.Preconditions;
import com.inno.life.common.annotiation.Log;
import com.inno.life.common.context.LoginUserContext;
import com.inno.life.common.entity.CommonReturnType;
import com.inno.life.controller.convert.MomentLikedDTOConverter;
import com.inno.life.controller.dto.MomentLikedDTO;
import com.inno.life.domain.entity.MomentLikedBO;
import com.inno.life.domain.service.MomentLikedDomainService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author sean
 * 动态点赞controller
 */
@RestController
@RequestMapping("/life/moment/liked")
@Slf4j
public class MomentLikedController {
    @Resource
    private MomentLikedDomainService momentLikedDomainService;

    /**
     * 点赞
     */
    @PostMapping("/add")
    @Log(operationType = "点赞")
    public CommonReturnType<Void> add(@RequestBody MomentLikedDTO momentLikedDTO){
        Preconditions.checkNotNull(momentLikedDTO.getToMomentId(),"动态id不能为空");
        Long userId = LoginUserContext.getUserId();
        momentLikedDTO.setFromId(userId);
        MomentLikedBO momentLikedBO = MomentLikedDTOConverter.INSTANCE.convertDTOToBO(momentLikedDTO);
        this.momentLikedDomainService.add(momentLikedBO);
        return CommonReturnType.success();
    }
}
